<html>
<head>
	<meta charset='utf-8' />
	<title>小区信息助手后台</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<style>
		@media screen and (max-width:450px){
			#content,.nav_div{width:98%;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
		@media screen and (min-width:450px){
			#content,.nav_div{width:450px;margin:0 auto}
			/*页面宽度900以下时 .abc的宽度为450*/
		}
	</style>
</head>
<body>
<div id='content' style='position:relative;border:0px solid'>
	<h1 style='text-align:center'>公共数据库设置</h1>
	
	<div style='text-align:center'>
		<div style='margin:10px 0'>
			库　名：<input id='db_name' type="text" />
		</div>
		<div style='margin:10px 0'>
			库　址：<input id='db_addr' type="text" />
		</div>

		<button id='submit'>提交</button>
		<button id='reset'>重置</button>
	</div>


</div>


</body>
</html>
<script src='../public/jquery.js'></script>
<script src='../public/fun.js'></script>
<script>
$(function(){
	//底部导航与显示页面
	$.ajax({
		url:'after_template_bottom_nav.html',
		success(res){
			$('body').append(res);
		}
	});


	//提交
	$('#submit').click(function(){
		var db_addr = $('#db_addr').val().trim();
		var db_name = $('#db_name').val().trim();
		var data = {
			type:'public_database_set',
			db_addr:db_addr,
			db_name:db_name,
		};
		Ajax2(data,function(res){
			//C(res);
			switch(res){
				case 'err1':A('缺少必填项！');break
				default:
				if(/^\[.*\]$/.test(res)){
					sessionStorage.public_database = res;
				}else{
					sessionStorage.public_database = '';
				}
				A('设置成功！');
			}
		});
	});

	//获取公共数据库
	if(!sessionStorage.public_database){
		C('after');
		Ajax2({type:'get_public_database'},function(res){
			C(res);
			if(/^\[.*\]$/.test(res)){
				sessionStorage.public_database = res;
				SetInput();
			}
		})
	}else{
		SetInput();
	}
	
	function SetInput(){
		if(sessionStorage.public_database){
			var tmp1 = JSON.parse(sessionStorage.public_database);
			if(tmp1[0] && tmp1[1]){
				$('#db_addr').val(tmp1[1]);
				$('#db_name').val(tmp1[0]);
			}

		}
	}


});
</script>